<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 100px;
            height: 100px;
            background-color: red;
            line-height: 100px;
            color: white;
            text-align: center;
            border-radius: 50%;
            position: absolute;
        }
    </style>
</head>
<body>
    <div id="box">点击，移动</div>
    <script>
        var boxObj = document.getElementById("box");
        boxObj.onclick=function(e){
            animate(boxObj,{'left':200,'top':50})
        }
        function animate(boxObj,options){
            clearInterval(boxObj.timer);
            boxObj.timer=setInterval(function(){
                var flag=true;
                //js对象的遍历,使用 for...in
                for(var k in options){
                    //||或截断,如果parseInt的值为null，则leader为0
                    var leader=parseInt(getStyle(boxObj,k))||0;
                    var target=options[k];
                    //设置步长
                    var step=(target-leader)/10;
                    step=step>0?Math.cell(step):Math.floor(step);
                    leader+=step;
                    boxObj.style[k]
                }
            },20);
        }
        //获取元素当前的样式值
        function getStyle(obj,key){
            if(window.getComputedStyle){
                return window.getComputedStyle(obj,null)[key];
            }else{
                return obj.currentStyle[key];
            }
        }
    </script>
</body>
</html>